import app from '@system.app';

export async function plus(params) {
    try {
        const action = {};
        action.bundleName = "com.sengmitnick.timelogger";
        action.abilityName = "com.sengmitnick.timelogger.PlusAbility";
        action.data = params;
        action.messageCode = 1001;
        action.abilityType = 0;

        var result = await FeatureAbility.startAbility(action);
        console.info('plus result is:' + JSON.stringify(result));
    } catch (err) {
        console.error('plus failed. Cause: ' + JSON.stringify(err));
    }
    return
}

export default {
    data: {
        path: '',
        loading: false,
        name: '未知状态',
        icon: 'unknown',
        color: "#007DFF"
    },
    onInit() {
        this.start();
    },
    async start() {
        if (this.loading) return;
        this.loading = true;
        await plus({ name: this.name, icon: this.icon, color: this.color });
        this.loading = false;
        app.terminate();
    },
}